import React from "react";
import styles from "./PostNew.module.css";
import { Button, Form, Input, InputNumber } from "antd";
import { Post_dao } from "./Post";
import moment from "moment";
import SelectUser from "./SelectUser";

interface Props {
    onSave: (data: Post_dao) => void;
}
/**
 * 帖子列表
 * */
const PostNew = ({ onSave }: Props) => {
    const onFinish = (data: any) => {
        const date = moment().format("YYYY-MM-DD HH:MM:SS");
        onSave && onSave({ ...data, date });
    };
    return (
        <div className={styles.main}>
            <Form layout={"vertical"} onFinish={onFinish}>
                <Form.Item label="ID" name={"id"} rules={[{ required: true }]}>
                    <InputNumber style={{ width: "100%" }} />
                </Form.Item>
                <Form.Item
                    label="标题"
                    name={"title"}
                    rules={[{ required: true }]}
                >
                    <Input style={{ width: "100%" }} />
                </Form.Item>
                <Form.Item
                    label="作者"
                    name={"author"}
                    rules={[{ required: true }]}
                >
                    <SelectUser />
                </Form.Item>
                <Form.Item
                    label="内容"
                    name={"content"}
                    rules={[{ required: true }]}
                >
                    <Input.TextArea style={{ width: "100%" }} />
                </Form.Item>
                <Form.Item>
                    <Button type="primary" htmlType="submit">
                        保存
                    </Button>
                </Form.Item>
            </Form>
        </div>
    );
};
export default PostNew;
